package com.agriculture.monitor.controller;


import com.agriculture.monitor.base.ResultInfo;
import com.agriculture.monitor.dto.BasePage;
import com.agriculture.monitor.entity.Role;
import com.agriculture.monitor.service.IRoleService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author admin
 * @since 2024-03-21
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    IRoleService roleService;

    @ApiOperation(value = "查询", notes = "查询")
    @PostMapping("/page")
    public ResultInfo<Page<Role>> page(@RequestBody BasePage basePage) {
        return ResultInfo.OK(roleService.listPage(basePage));
    }

    @ApiOperation(value = "查询", notes = "查询")
    @PostMapping("/list")
    public ResultInfo<List<Role>> list() {
        return ResultInfo.OK(roleService.list());
    }


    @ApiOperation(value = "保存", notes = "保存")
    @PostMapping("/save")
    public ResultInfo<?> saveData(@RequestBody Role role) {
        return ResultInfo.OK(roleService.save(role));
    }

    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public ResultInfo<?> delete(@RequestBody Role role) {
        return ResultInfo.OK(roleService.removeById(role.getId()));
    }
}
